package com.gonsin.gview.model.dynamic.form;

import com.gonsin.gview.annotations.enums.InputType;
import com.gonsin.gview.model.GFormItemModel;
import com.gonsin.gview.model.data.GSimpleListDataModel;
import com.gonsin.gview.model.dynamic.data.DynamicSimpleListData;
import com.gonsin.gview.model.dynamic.table.DynamicSearchFilter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@ApiModel("文本输入框的描述")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DynamicTextInput extends DynamicFormItem implements DynamicSearchFilter {

    @ApiModelProperty("text_input表示文本框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
    private String itemType = "text_input";

    @ApiModelProperty("是否必选")
    private boolean required = true;

    @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
    private String keyName;

    @ApiModelProperty("显示的名字")
    private String name;

    @ApiModelProperty("输入框内提示的文本")
    private String placeholder;

    @ApiModelProperty("输入的类型 有text/number/password/re_password/text_pull")
    private InputType inputType;

    @ApiModelProperty("文本内容校验的正则表达式")
    private String regular;

    @ApiModelProperty("校验不通过时提示的文本")
    private String regularMessage;

    @ApiModelProperty("动态显示的js脚本，用于控制特定情况下该输入框的隐藏和显示")
    private String showIf = "1";

    @ApiModelProperty("根据情况禁用")
    private String disableIf = "0";

    @ApiModelProperty("文本框支持模糊搜索时，下拉的数据源")
    private DynamicSimpleListData simpleListData;

    @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
    private String onChangeAction;


    public static DynamicTextInputBuilder builder() {
        return new DynamicTextInputBuilder();
    }

    public static final class DynamicTextInputBuilder {
        @ApiModelProperty("是否必选")
        private boolean required = true;

        @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
        private String keyName;

        @ApiModelProperty("显示的名字")
        private String name;

        @ApiModelProperty("输入框内提示的文本")
        private String placeholder;

        @ApiModelProperty("输入的类型 有text/number/password/re_password/text_pull")
        private InputType inputType;

        @ApiModelProperty("文本内容校验的正则表达式")
        private String regular;

        @ApiModelProperty("校验不通过时提示的文本")
        private String regularMessage;

        @ApiModelProperty("动态显示的js脚本，用于控制特定情况下该输入框的隐藏和显示")
        private String showIf = "1";

        @ApiModelProperty("根据情况禁用")
        private String disableIf = "0";

        @ApiModelProperty("文本框支持模糊搜索时，下拉的数据源")
        private DynamicSimpleListData simpleListData;

        @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
        private String onChangeAction;

        private DynamicTextInputBuilder() {
        }

        public DynamicTextInputBuilder required(boolean required) {
            this.required = required;
            return this;
        }

        public DynamicTextInputBuilder keyName(String keyName) {
            this.keyName = keyName;
            return this;
        }

        public DynamicTextInputBuilder name(String name) {
            this.name = name;
            return this;
        }

        public DynamicTextInputBuilder placeholder(String placeholder) {
            this.placeholder = placeholder;
            return this;
        }

        public DynamicTextInputBuilder inputType(InputType inputType) {
            this.inputType = inputType;
            return this;
        }

        public DynamicTextInputBuilder regular(String regular) {
            this.regular = regular;
            return this;
        }

        public DynamicTextInputBuilder regularMessage(String regularMessage) {
            this.regularMessage = regularMessage;
            return this;
        }

        public DynamicTextInputBuilder showIf(String showIf) {
            this.showIf = showIf;
            return this;
        }

        public DynamicTextInputBuilder disableIf(String disableIf) {
            this.disableIf = disableIf;
            return this;
        }

        public DynamicTextInputBuilder simpleListData(DynamicSimpleListData simpleListData) {
            this.simpleListData = simpleListData;
            return this;
        }

        public DynamicTextInputBuilder onChangeAction(String onChangeAction) {
            this.onChangeAction = onChangeAction;
            return this;
        }

        public DynamicTextInput build() {
            DynamicTextInput dynamicTextInput = new DynamicTextInput();
            dynamicTextInput.setRequired(required);
            dynamicTextInput.setKeyName(keyName);
            dynamicTextInput.setName(name);
            dynamicTextInput.setPlaceholder(placeholder);
            dynamicTextInput.setInputType(inputType);
            dynamicTextInput.setRegular(regular);
            dynamicTextInput.setRegularMessage(regularMessage);
            dynamicTextInput.setShowIf(showIf);
            dynamicTextInput.setDisableIf(disableIf);
            dynamicTextInput.setSimpleListData(simpleListData);
            dynamicTextInput.setOnChangeAction(onChangeAction);
            return dynamicTextInput;
        }
    }
}
